﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jemer.Domain;
using Jemer.Data;
using Jemer.Data.Infrastructure;
using Jemer.Domain.Entities;
using Jemer.Data.Repositories;

namespace Jemer.Service
{
    
    public interface IUserCollectionService
    {
        IQueryable<UserCollection> GetUserCollections();
        UserCollection GetUserCollection(int id);
        void CreateUserCollection(UserCollection userCollection);
        void DeleteUserCollection(int id);
        void SaveUserCollection();
    }
    
    public class UserCollectionService : IUserCollectionService
    {
        private readonly IUserCollectionRepository userCollectionRepository;
        private readonly IUnitOfWork unitOfWork;
        public UserCollectionService(IUserCollectionRepository userCollectionRepository, IUnitOfWork unitOfWork)
        {
            this.userCollectionRepository = userCollectionRepository;
            this.unitOfWork = unitOfWork;
        }  
        #region IUserCollectionService Members

        public IQueryable<UserCollection> GetUserCollections()
        {
            var userCollections = userCollectionRepository.GetAll();
            return userCollections;
        }

        public UserCollection GetUserCollection(int id)
        {
            var userCollection = userCollectionRepository.GetById(id);
            return userCollection;
        }

        public void CreateUserCollection(UserCollection userCollection)
        {
            userCollectionRepository.Add(userCollection);
            SaveUserCollection();
        }

        public void DeleteUserCollection(int id)
        {
            var userCollection = userCollectionRepository.GetById(id);
            userCollectionRepository.Delete(userCollection);
            SaveUserCollection();
        }

        public void SaveUserCollection()
        {
            unitOfWork.Commit();
        }

        #endregion
    }
    
    
}